package com.lez.flowpractice2.utils

import java.io.InputStream
import java.io.OutputStream

inline fun InputStream.copyToTwo(out: OutputStream,bufferSize: Int = DEFAULT_BUFFER_SIZE, progress: (Long)-> Unit): Long{

    var bytesCopied: Long = 0
    val buffer = ByteArray(bufferSize)
    var bytes = read(buffer)
    while (bytes >= 0){
        out.write(buffer,0,bytes)
        bytesCopied += bytes
        bytes = read(buffer)

        progress(bytesCopied)
    }
    return bytesCopied
}